<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="园所名称" prop="schoolName">
        <el-input v-model="queryParams.schoolName" placeholder="请输入园所名称" @input="handleInput" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="结业时间" prop="graduationDate">
            <el-date-picker
              v-model="queryParams.graduationDate"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd"
              :editable="false"
              type="date"
              size="small"
              placeholder="请选择结业时间">
            </el-date-picker>
      </el-form-item>
      <el-form-item label="结业类型" prop="completeType">
        <el-select v-model="queryParams.completeType" placeholder="请选择结业类型" clearable size="small">
          <el-option
            v-for="dict in completeTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学生姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入学生姓名" @input="handleStudednt"   maxlength="25" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
    </el-form-item>
    </el-form>
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['student:studentCheck:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['student:studentCheck:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['student:studentCheck:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['student:studentCheck:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="studentCheckList" style="width: 100%;">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column type="index" align="center" label="序号" :index="customeIndex" width="80"></el-table-column>
      <el-table-column label="园所名称" align="center" prop="schoolName"  width="150" />
      <el-table-column label="学生姓名" align="center" prop="name" />
      <!-- <el-table-column label="年级" align="center" prop="year" /> -->
      <!-- <el-table-column label="班级" align="center" prop="className" /> -->
      <el-table-column label="身份证" align="center" prop="idcard" :show-overflow-tooltip="true" />
      <!-- <el-table-column label="年龄" align="center" prop="type"  /> -->
      <el-table-column label="性别" align="center" prop="sex"  :formatter="sexFormat" />
      <el-table-column label="结业时间" align="center" prop="graduationDate" />
      <el-table-column label="结业类型" align="center" prop="completeType" :formatter="completeTypeFormat"/>
      <el-table-column label="家长姓名" align="center" prop="jzxm" />
      <el-table-column label="家长电话" align="center" prop="jzdh" />
      <el-table-column label="病史" align="center" prop="medicalHistory" />
      <el-table-column label="过敏史" align="center" prop="allergicHistory" />
      <el-table-column label="接种信息" align="center" prop="vaccinationIf" />
      <el-table-column label="家庭地址" align="center" prop="jtzz"  />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['student:studentCheck:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['student:studentCheck:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetails(scope.row)" >详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" 
      @pagination="getList" />

    <!-- 在园幼儿信息详情 -->
    <el-dialog title="在园幼儿信息详情" :visible.sync="open" width="700px" append-to-body>
         <el-descriptions title=""  :column="2">
             <el-descriptions-item label="姓名">{{ childrenData.name }}</el-descriptions-item>
             <!-- <el-descriptions-item label="年龄">{{ childrenData.age }}</el-descriptions-item> -->
             <el-descriptions-item label="性别" >{{ childrenData.sex }}</el-descriptions-item>
             <el-descriptions-item label="年级">{{ childrenData.year }}</el-descriptions-item>
             <!-- <el-descriptions-item label="班级">{{ childrenData.class }}</el-descriptions-item> -->
             <el-descriptions-item label="家长姓名">{{ childrenData.jzxm }}</el-descriptions-item>
             <el-descriptions-item label="家长电话">{{ childrenData.jzdh }}</el-descriptions-item>
             <el-descriptions-item label="家庭地址" :span='2' >{{childrenData.jtzz }}</el-descriptions-item>
             <el-descriptions-item label="病史" :span='2' >{{ childrenData.medicalHistory }}</el-descriptions-item>
             <el-descriptions-item label="过敏史" :span='2' >{{ childrenData.allergicHistory }}</el-descriptions-item>
             <el-descriptions-item label="接种信息" :span='2' >{{ childrenData.vaccinationIf }}</el-descriptions-item>
             <!-- <el-descriptions-item label="备注">
              备注信息
             </el-descriptions-item> -->
             <!-- <el-descriptions-item label="联系地址">江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item> -->
         </el-descriptions>
        <!-- <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div> -->
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess"
        :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的考勤数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { studentlist} from "@/api/qu/yexxgl";
  import { selectRoom } from "@/api/base/room";
  import { getToken } from "@/utils/auth";
  import { selectStudent } from "@/api/base/student";

  export default {
    name: "",
    data() {
      return {
        studentType:'',
        pickerOptions: {
              disabledDate(time) {
                return time.getTime() > Date.now();
              },  
            },
        childrenData:{
          name:'张三',age:'5',sex:'男',class:'小二班',father:'张一',mother:'王五',medicalHistory:'关于病史的信息'
        },
        completeTypeOptions:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 宿舍数据
        roomList: [],
        queryRoomList: [],
        //学生数据
        studentList: [],
        // 宿舍考勤表格数据
        studentCheckList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 考勤类型字典
        typeOptions: [],
        // 导入参数
        upload: {
          // 是否显示弹出层
          open: false,
          // 弹出层标题
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: {
            Authorization: "Bearer " + getToken()
          },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/student/studentCheck/importData"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          schoolName: null,
          graduationDate:'',
          completeType:'',
          year:'',
          name: null,
          type: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          batchs: [{ required: true, message: "学生不能为空", trigger: "blur" }],
          roomId: [{ required: true, message: "宿舍不能为空", trigger: "blur" }],
          checkDate: [{ required: true, message: "考勤日期不能为空", trigger: "blur" }],
          type: [{ required: true, message: "考勤类型不能为空", trigger: "blur" }]
        }
      };
    },
    created() {
      this.getDicts("sys_user_sex").then(response => {
         this.sexOptions = response.data;
       });
       this.getDicts("complete_type").then(response => {
         this.completeTypeOptions = response.data;
       });
      this.getDicts("student_type").then(response => {
         response.data.forEach(item => {
           if(item.dictLabel=='结业幼儿') 
          this.studentType=item.dictValue;
         });
        
         this.getList();
      });
    },
    methods: {
       // 序号
       customeIndex(index){
         return index+1+(this.queryParams.pageNum-1)*this.queryParams.pageSize
      },
      /** 在园幼儿列表 */
      async  getList() {
        this.loading = true;
        try {
          const obj = {
            type:this.studentType,
            schoolName:this.queryParams.schoolName,
            graduationDate:this.queryParams.graduationDate,
            completeType:this.queryParams.completeType,
            year:this.queryParams.year,
            name:this.queryParams.name,
            pageNum: this.queryParams.pageNum,
            pageSize:this.queryParams.pageSize,
          }
           const data=  await studentlist(obj);
           this.studentCheckList=data.rows;
           this.total=data.total
           this.loading = false;
        } catch (error) {
          console.log(error);
        }
      },
       // 性别字典翻译
     sexFormat(row, column) {
       return this.selectDictLabel(this.sexOptions, row.sex);
     },
     completeTypeFormat(row, column) {
       return this.selectDictLabel(this.completeTypeOptions, row.completeType);
     },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          stuId: null,
          batchs: null,
          roomId: null,
          checkDate: null,
          addUser: null,
          addTime: null,
          type: null,
          comment: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
     
      handleInput(val){
        let regtszf = /[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]/g // 特殊字符正则
        let regkg = /[ ]/g// 空格正则
        this.queryParams.schoolName = val.replace(regtszf, '').replace(regkg, '')
         },
      handleStudednt(val){
       let regkg = /[ ]/g// 空格正则
       this.queryParams.name = val.replace(regkg, '')
      },
      //详情
      handleDetails(item){
          this.childrenData=item
          this.open=true
          console.log('详情');
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportStudentCheck(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "宿舍考勤导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        importTemplate().then(response => {
          this.download(response.msg);
        });
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, "导入结果", {
          dangerouslyUseHTMLString: true
        });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      }
    }
  };
</script>
